package com.shoppingmall.activity.mine;

import android.os.Bundle;
import android.view.View;

import com.example.zyh.toolslib.base.BaseActivity;
import com.example.zyh.toolslib.widget.TitleBar;
import com.google.android.material.tabs.TabLayout;
import com.shoppingmall.R;
import com.shoppingmall.fragment.MineCollectGoodsFragment;
import com.shoppingmall.fragment.MineCollectStoresFragment;
import com.shoppingmall.fragment.MineOrderListFragment;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 2020/3/19
 * 描述：我的订单
 */
public class MineOrderActivity extends BaseActivity {
    @BindView(R.id.title_bar)
    TitleBar titleBar;
    @BindView(R.id.tab_layout)
    TabLayout tabLayout;
    @BindView(R.id.view_pager)
    ViewPager viewPager;

    private String[] title = {"全部", "待付款", "待发货", "待收货", "已完成"};
    private int selectPos = 0;
    private List<MineOrderListFragment> fragmentList;

    @Override
    protected int initLayout() {
        return R.layout.activity_mine_order;
    }

    @Override
    protected void initView() {
        selectPos = getIntent().getIntExtra("state", 0);
        fragmentList = new ArrayList<>();
        fragmentList.add(MineOrderListFragment.newInstance(0));
        fragmentList.add(MineOrderListFragment.newInstance(1));
        fragmentList.add(MineOrderListFragment.newInstance(2));
        fragmentList.add(MineOrderListFragment.newInstance(3));
        fragmentList.add(MineOrderListFragment.newInstance(4));
        ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
        viewPager.setOffscreenPageLimit(5);
        viewPager.setAdapter(viewPagerAdapter);
        tabLayout.setupWithViewPager(viewPager);
        tabLayout.getTabAt(selectPos).select();
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initEvent() {
        titleBar.setLeftLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    private class ViewPagerAdapter extends FragmentPagerAdapter {

        public ViewPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return title[position];
        }
    }

}
